package com.cy.utils;

import com.cy.sdk.sms.SMSService;
import com.cy.sdk.sms.impl.LuosimaoSMS;

import java.text.MessageFormat;
import java.util.Date;

public class SMSKit {
    public static final String MSG_SIGNATURE = "【科贝尔】";
    private static final String msgCheckCodeContent = "{0}欢迎使用科贝尔，您的验证码:{1},三分钟内有效。【科贝尔】";
    private static final int CHECKCODENUM = 4;
    private static SMSService smsService = new LuosimaoSMS();

    public static SMSService getSmsService() {
        return smsService;
    }

    public static void setSmsService(SMSService smsService) {
        SMSKit.smsService = smsService;
    }

    public static String sendRandomCheckCode(String mobile,String accountName) {
        if(null == smsService){
            setSmsService(new LuosimaoSMS());
        }
        String checkCode = RandomCodeGenerator.generateCheckCodeString(CHECKCODENUM);
        String content = MessageFormat.format(msgCheckCodeContent, accountName, checkCode, new Date());
        sendMessage(mobile, content);
        return checkCode;
    }

    public static void sendMessage(final String mobile, final String msg) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                smsService.sendSMS(mobile, msg);
            }
        }).run();
    }

}
